﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TruckWatch.Cloud.Models.EF;

namespace TruckWatch.Cloud.BusinessLogic
{
    public static class DriverBLEF
    {
        public static Driver GetDriverByUserId(string userId, TruckWatchEntities context = null, bool throwExceptionIfNotFound = false)
        {
            if (context == null)
                context = new TruckWatchEntities();

            Driver driver = context.Drivers.FirstOrDefault(d => d.UserId == userId);
            if (driver == null && throwExceptionIfNotFound)
                throw new Exception(string.Format("Driver with UserId {0} not found", userId));

            return driver;
        }

        public static List<Driver> GetAllDrivers()
        {
            TruckWatchEntities context = new TruckWatchEntities();

            return context.Drivers.ToList();
        }
    }
}
